#include "MainPage.h"
#include "Container.h"
#include "IniProgram.h"
#include "Game_page.h"

Container *Main_Page = nullptr;
Container *Game_start_btn = nullptr;
Container *Continue_Game_Btn = nullptr;
Container *Exit_Game_Btn = nullptr;
Container *Clothing_Btn = nullptr;



void Display_Main_Page()
{
    manager.set_top(Main_Page);
}

void Continue_Game()
{
    if (gameSnake == nullptr)
    {
        Display_Reminder_Page();
        return;
    }
    manager.set_top(Game_Page);
}

void Game_Start()
{
    reStart();
    manager.set_top(Game_Page);
}

void Exit_Game()
{
    lcd.clear();
    ;
    exit(1);
}

void create_Main_Page()
{
    Main_Page = new Container(800, 480);
    Main_Page->set_background_image("./res/main_page.bmp");
    Main_Page->set_Visible(true);
    Main_Page->set_Event_Type(CLICK);
    manager.add(Main_Page);
    manager.set_top(Main_Page);

    Continue_Game_Btn = new Container(Main_Page, 188, 56);
    Continue_Game_Btn->set_background_image("./res/Continue_Game.bmp", true, 0x00ffffff);
    Continue_Game_Btn->set_Visible(true);
    Continue_Game_Btn->align(RIGHT_CENTER, -40, -80);
    Continue_Game_Btn->set_Event_Type(CLICK);
    Continue_Game_Btn->set_Event(Continue_Game);

    Game_start_btn = new Container(Main_Page, 188, 63);
    Game_start_btn->set_background_image("./res/Game_start_main.bmp", true, 0x00ffffff);
    Game_start_btn->set_Visible(true);
    Game_start_btn->align(RIGHT_CENTER, -40, 0);
    Game_start_btn->set_Event_Type(CLICK);
    Game_start_btn->set_Event(Game_Start);

    Exit_Game_Btn = new Container(Main_Page, 183, 57);
    Exit_Game_Btn->set_background_image("./res/Exit_Game.bmp", true, 0x00ff0000);
    Exit_Game_Btn->set_Visible(true);
    Exit_Game_Btn->align(RIGHT_CENTER, -40, 80);
    Exit_Game_Btn->set_Event_Type(CLICK);
    Exit_Game_Btn->set_Event(Exit_Game);

    Clothing_Btn = new Container(Main_Page, 70, 70);
    Clothing_Btn->set_background_image("./res/Clothing.bmp", true, 0x00ffffff);
    Clothing_Btn->set_Visible(true);
    Clothing_Btn->align(BOTTOM_RIGHT, -20, -20);
    Clothing_Btn->set_Event_Type(CLICK);
    Clothing_Btn->set_Event(Display_Clothing_Page);

    create_Clothing_Page();
}
